package com.david.rabbitmq.ttl.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author David
 * @version V1.0
 * @Package com.david.rabbitmq.ttl.listener
 * @date 2021/7/18 15:49
 */
@Component
public class MeetingMessageListener {

    @RabbitListener(queues = "queue.delayed")
    public void onMessage(Message message, Channel channel) throws IOException {
        System.out.println("监听者收到消息："+new String(message.getBody(), message.getMessageProperties().getContentEncoding()));
        // 消息确认
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
